package com.hugo.maomi_first.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hugo.maomi_first.R;
import com.hugo.maomi_first.bean.HomeGoodsBean;
import com.hugo.maomi_first.helper.BaseAdapterHelper;
import com.hugo.maomi_first.utils.ImageLoader;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/7/5.
 */
public class HomeGoodsAdapter extends BaseAdapterHelper<HomeGoodsBean.DataBean.ItemsBean> {

    public HomeGoodsAdapter(Context context, List<HomeGoodsBean.DataBean.ItemsBean> list) {
        super(context, list);
    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent, List<HomeGoodsBean
            .DataBean.ItemsBean> list, LayoutInflater inflater) {
        ViewHolder mHolder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_listview_home, parent, false);
            mHolder = new ViewHolder(convertView);
            convertView.setTag(mHolder);
        }else {
            mHolder = (ViewHolder) convertView.getTag();
        }
        mHolder.tvItemName.setText(list.get(position).getTitle());
        mHolder.tvItemPrice.setText(list.get(position).getPrice().getCurrent() + "");
        ImageLoader.getInstance().displayImage(context,list.get(position).getImg().getImg_url(),mHolder.ivItemIcon);
        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.iv_item_icon)
        ImageView ivItemIcon;
        @Bind(R.id.tv_item_name)
        TextView tvItemName;
        @Bind(R.id.tv_item_price)
        TextView tvItemPrice;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
